﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

[Serializable]
public class TankManager1
{
    public Color m_PlayerColor;
    public Transform m_TransformPoint;
    [HideInInspector] public int m_PlayerNum;
    [HideInInspector] public string m_ColorPlayerText;
    [HideInInspector] public GameObject m_Instance;
    [HideInInspector] public float m_wins = 0;
    
    private TankMovement1 m_TankMovement1;
    private TankShooting1 m_TankShooting1;
    private GameObject m_Canvas;


    public void SetUp()
    {
        m_TankMovement1 = m_Instance.GetComponent<TankMovement1>();
        m_TankShooting1 = m_Instance.GetComponent<TankShooting1>();
        m_Canvas = m_Instance.GetComponentInChildren<Canvas>().gameObject;

        m_TankMovement1.m_PlayerNum = m_PlayerNum;
        m_TankShooting1.m_PlayerNum = m_PlayerNum; 

        m_ColorPlayerText = "<color=#" + ColorUtility.ToHtmlStringRGB(m_PlayerColor) + ">PLAYER " + m_PlayerNum + "</color>";
        MeshRenderer[] randers = m_Instance.GetComponentsInChildren<MeshRenderer>();
        for (int i = 0; i < randers.Length; i++)
        {
            randers[i].material.color = m_PlayerColor;
        }

    }

    public void DisableControl()
    {
        m_TankMovement1.enabled = false;
        m_TankShooting1 .enabled = false;

        m_Canvas.SetActive(false);
    }

    public void EnableControl()
    {
        m_TankMovement1 .enabled = true;
        m_TankShooting1.enabled = true;

        m_Canvas .SetActive(true);
    }

    public void Reset()
    {
        m_Instance.transform.position = m_TransformPoint.position;
        m_Instance.transform.rotation = m_TransformPoint.rotation;

        m_Instance.SetActive(false);
        m_Instance.SetActive(true);
    }
}
